import $ from "jquery";
import {url} from "../../util/config";
import {message} from "antd";
import login from "../login";

function getNewLogin(activityId) {
    return getActivityContent(activityId)
}

export default function getActivityContent(activityId) {
    console.log(activityId)
    let token = localStorage.getItem("token")
    let activityContent = null
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`Activity/GetActivityContent?ActivityId=${activityId}`,
        type: 'get',
        success: function (result) {
            let tmp = result.result;
            if(tmp=="Token過期請重新登錄"){
                login(localStorage.getItem("account"),localStorage.getItem("password"));
                activityContent = getNewLogin(activityId)
            }else {
                activityContent = {
                    new:tmp.ARTICLE_NEW,
                    key:tmp.ID,
                    name:tmp.NAME, 		//活动名称
                    content:tmp.CONTENT, 	//活动内容
                    figure:tmp.IMAGE_URL,	//活动配图，不传值使用图片
                    desc:tmp.ARTICLE_DESC,		//活动描述
                    status:tmp.TOP_STATUS,	//是否置顶，不传值默认否
                    applyStartTime:tmp.ACTIVITY_APPLY_START_TIME, //活动报名时间，不传值默认无
                    applyEndTime:tmp.ACTIVITY_APPLY_END_TIME,	//活动报名结束时间，不传值默认无
                    startTime:tmp.ACTIVITY_START_TIME,  //活动开始时间
                    endTime:tmp.ACTIVITY_END_TIME,	//活动结束时间，logo同步失效
                    station:tmp.ACTIVITY_STATION, //活动地点，不传值默认无
                    attachUrls:tmp.ATTACH_URL, 		//附件的url数组
                    attachNames:tmp.ATTACH_NAME,	//附件的原名称数组
                    attachNum:tmp.ATTACH_NUM    		//附件数
                }
            }
        },
        error:function (error) {
            message.error("请求异常")
        }
    })
    return activityContent;

}

